#include "threadPool.h"
#include "train.h"

int netDriveLs(const char *pathname, int netfd)
{
    DIR *pdir = opendir(pathname);
    ERROR_CHECK(pdir, NULL, "opendir");
    char buf[4096] = {0};
    struct dirent *pdirent;
    errno = 0;
    int i = 0;
    while ((pdirent = readdir(pdir)) != NULL)
    {
        strcat(buf, pdirent->d_name);
        strcat(buf, "   ");
    }
    if (errno != 0)
    {
        perror("readdir");
        return -1; // 判断是否发生错误
    }
    closedir(pdir);
    train_t train;
    train.len = strlen(buf);
    memcpy(train.data, buf, train.len);
    send(netfd, &train, sizeof(int) + train.len, MSG_NOSIGNAL);
    return 0;
}
